#
# This file is a part of the open-eBackup project.
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
# If a copy of the MPL was not distributed with this file, You can obtain one at
# http://mozilla.org/MPL/2.0/.
#
# Copyright (c) [2024] Huawei Technologies Co.,Ltd.
#
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
#

import sys

from dws.commons.common import log
from common.util.check_utils import is_valid_id
from common.common import output_result_file


def do_exec(pid):
    log.info(f"Enter, pid:{pid}")

    output_result_file(pid, {"user": "root", "group": "rdadmin", "fileMode": "555"})
    log.info(f"Query permission suc, {pid}")

    return True


if __name__ == '__main__':
    if len(sys.argv) < 2:
        log.error("Param is wrong.")
        sys.exit(1)

    if not is_valid_id(sys.argv[1]):
        log.warn(f"pid is invalid")
        sys.exit(1)

    try:
        if not do_exec(sys.argv[1]):
            log.error(f"Do exec failed, pid: {sys.argv[1]}.")
            sys.exit(1)
    except Exception as err:
        log.error(f"Err: {err}, pid: {sys.argv[1]}")
        sys.exit(1)

    sys.exit(0)
